package com.fen.service.lmpl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fen.dao.UserMapper;
import com.fen.pojo.User;
import com.fen.service.UserServict;
import com.fen.utils.Md5Utils;
import com.fen.vo.requset.RequsetUserov;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;

/** 
* @Description: userservice实现类 
* @Author: lijiafen
* @Date:  2021/10/29
* @Time: 21:15
* @eamil: 2368044269@qq.com
*/ 
@Service
public class UserServicelmpl extends ServiceImpl<UserMapper,User> implements UserServict{


    @Override
    public User SelectuserByphone(String telephone) {
        /**
         * @Description: 用电话号码查询有没有这个用户
         * @Author: lijiafen
         * @Date:  2021/10/30
         * @Time: 14:00
         * @eamil: 2368044269@qq.com
         */
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
         queryWrapper.eq("telephone", telephone);
        return getOne(queryWrapper);
    }

    @Override
    public boolean adduser(RequsetUserov userov) {
        User user=new User();
        BeanUtils.copyProperties(userov,user);
        user.setType(0);
        user.setPassword(Md5Utils.hash(userov.getPassword()));
        user.setCreateTime(LocalDateTime.now());
        System.out.println(user);
        return save(user);
    }

    @Override
    public User SelectuserBypassword(String password) {
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        password=Md5Utils.hash(password);
        queryWrapper.eq("password", password);
        return getOne(queryWrapper);
    }

    @Override
    public User SelectuserByname(String name) {
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",name);
        return getOne(queryWrapper);
    }

    @Override
    public User sleel() {
        return null;
    }
}
